package wang.chuangen.session.vo;

import java.util.HashSet;
import java.util.Set;

import org.apache.catalina.Manager;
import org.apache.catalina.session.StandardSession;

/**
 * 继承自StandardSession
 * 记录Attributes改变
 * @author 王传根
 * @date 2016-5-11下午12:15:06
 */
public class RedisSession extends StandardSession{

	private static final long serialVersionUID = -8809591532494649456L;
	
	/**
	 * 记录session Attributes 更改
	 */
	protected Set<String> changedKeys=new HashSet<String>();
	
	/**
	 * 标记加载状态
	 */
	protected boolean onload;

	public RedisSession(Manager manager) {
		super(manager);
	}
	
	public Set<String> getChangedKeys(){
		return changedKeys;
	}
	
	public void onload(boolean onload){
		this.onload=onload;
	}

	@Override
	public void removeAttribute(String name, boolean notify) {
		super.removeAttribute(name, notify);
		if(!onload)changedKeys.add(name);
	}

	@Override
	public void removeAttribute(String name) {
		super.removeAttribute(name);
		if(!onload)changedKeys.add(name);
	}

	@Override
	protected void removeAttributeInternal(String name, boolean notify) {
		super.removeAttributeInternal(name, notify);
		if(!onload)changedKeys.add(name);
	}

	@Override
	public void setAttribute(String name, Object value, boolean notify) {
		super.setAttribute(name, value, notify);
		if(!onload)changedKeys.add(name);
	}

	@Override
	public void setAttribute(String name, Object value) {
		super.setAttribute(name, value);
		if(!onload)changedKeys.add(name);
	}
}
